﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CamDo.DTO;
using System.Data.SqlClient;
using System.Data;

namespace CamDo.DAO
{
    class NguoiDung
    {
        private NhanVien nhanVienDTO;

        internal NhanVien NhanVienDTO
        {
            get { return nhanVienDTO; }
            set { nhanVienDTO = value; }
        }
        private Connect connectDTO;

        internal Connect ConnectDTO
        {
            get { return connectDTO; }
            set { connectDTO = value; }
        }
        SqlConnection connect;
        String error = "";

        public String Error
        {
            get { return error; }
            set { error = value; }
        }
        public SqlConnection Connect
        {
            get { return connect; }
            set { connect = value; }
        }
        public NguoiDung()
        {
            this.nhanVienDTO = new NhanVien();
            this.connectDTO = new Connect();
            this.connect = this.connectDTO.GetConnect();

        }
        public Boolean checkLogin(String userName, String password)
        {
            Boolean result = false;
            try
            {
                this.connect.Open();
                string sql = "select * from NGUOI_DUNG where NGUOI_DUNG.MaNguoiDung='" + userName + "' AND NGUOI_DUNG.MatKhau='" + password + "'";
                SqlCommand sqlcmd = new SqlCommand(sql, this.connect);
                sqlcmd.ExecuteNonQuery();
                SqlDataReader rdr = sqlcmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    result = true;
                }


                rdr.Close();
                this.connect.Close();
            }
            catch (Exception ex)
            {
                error = "Loi " + ex.ToString();
                result = false;
            }
            return result;
        }

    }
}
